package com.worker.Multition;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 多例模式
 * 真假猴子
 * @author worker
 *
 */
public class Monkey {
/**
 *定义猴子的数量 
 */
private static int monkeySum = 2;
private static List<Monkey> list = new ArrayList<Monkey>();
private static List<String> listName = new ArrayList<String>();
private static int currentNum;
static {
	for(int i=0;i<monkeySum;i++) {
		list.add(new Monkey("猴子"+i));
	}
}
private Monkey() {}
private Monkey(String name) {
	listName.add(name);
}
public static Monkey getMonkey() {
	//随机获取猴子
	Random radom = new Random();
	currentNum = radom.nextInt(monkeySum);
	Monkey monkey =  list.get(currentNum);
	return monkey;
}
public static String getMonkeyName() {
	return listName.get(currentNum);
}
}
